/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rbh.risk.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;
import org.hibernate.annotations.GenericGenerator;

/**
 *
 * @author IT-Mafia
 */
@Entity
@Table(name = "rbh_risk_data")
@XmlRootElement
public class RiskData implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    @Basic(optional = false)
    @Column(name = "DATA_ID", nullable = false, length = 40)
    private String dataId;
    @Basic(optional = false)
    @Column(name = "DATA_ACCIDENT_DATETIME", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date dataAccidentDatetime;
    @Column(name = "DATA_CREATE_DATETIME", insertable = false, updatable = false, columnDefinition = "timestamp default current_timestamp")
    @Generated(value = GenerationTime.INSERT)
    @Temporal(TemporalType.TIMESTAMP)
    private Date dataCreateDatetime;
    @Column(name = "DATA_UPDATE_DATETIME", insertable = false, updatable = true)
    @Temporal(TemporalType.TIMESTAMP)
    private Date dataUpdateDatetime;
    @Column(name = "DATA_EVENT_DETAILS", length = 2048)
    private String dataEventDetails;
    @Column(name = "DATA_LOCATE", length = 255)
    private String dataLocate;
    @Column(name = "DATA_PRELIMINARY_RESOLVE", length = 2048)
    private String dataPreliminaryResolve;
    @Column(name = "DATA_CQI", length = 1024)
    private String dataCQI;
    @JoinColumn(name = "RBH_RISK_PROFILE_REVIEW_LEVEL_1", referencedColumnName = "PROFILE_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private Profile profileReviewLevel1;
    @JoinColumn(name = "RBH_RISK_PROFILE_REVIEW_LEVEL_2", referencedColumnName = "PROFILE_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private Profile profileReviewLevel2;
    @JoinColumn(name = "RBH_RISK_PROFILE_REVIEW_LEVEL_3", referencedColumnName = "PROFILE_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private Profile profileReviewLevel3;
    @JoinColumn(name = "RBH_RISK_PROFILE_CREATE", referencedColumnName = "PROFILE_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private Profile profileCreate;
    @JoinColumn(name = "RBH_RISK_PROFILE_UPDATE", referencedColumnName = "PROFILE_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private Profile profileUpdate;
    @JoinColumn(name = "RBH_RISK_SEVERITY_LEVEL_DETAIL", referencedColumnName = "SLDETAIL_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private SeverityLevelDetail severityLevelDetail;
    @JoinColumn(name = "RBH_RISK_WORKGROUP_CONNECTED", referencedColumnName = "WORKGROUP_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private Workgroup workgroupConnected;
    @JoinColumn(name = "RBH_RISK_WORKGROUP", referencedColumnName = "WORKGROUP_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private Workgroup workgroup;
    @JoinColumn(name = "RBH_RISK_CATEGORY", referencedColumnName = "CATEGORY_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private Category category;
    @JoinColumn(name = "RBH_RISK_MAIN_EVENT", referencedColumnName = "MAIN_EVENT_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private MainEvent mainEvent;
    @JoinColumn(name = "RBH_RISK_MAIN_CAUSE", referencedColumnName = "MAIN_CAUSE_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private MainCause mainCause;
    @JoinColumn(name = "RBH_RISK_SUB_EVENT", referencedColumnName = "SUB_EVENT_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private SubEvent subEvent;
    @JoinColumn(name = "RBH_RISK_SUB_CAUSE", referencedColumnName = "SUB_CAUSE_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private SubCause subCause;
    @JoinColumn(name = "PATIENT_HN", referencedColumnName = "hn")
    @ManyToOne(fetch = FetchType.LAZY)
    private Patient patient;
    @JoinColumn(name = "S_DRUGITMES_CORRECT", referencedColumnName = "icode")
    @ManyToOne(fetch = FetchType.LAZY)
    private DrugItems drugItemsTrue;
    @JoinColumn(name = "S_DRUGITMES_WRONG", referencedColumnName = "icode")
    @ManyToOne(fetch = FetchType.LAZY)
    private DrugItems drugItemsFalse;
    @JoinTable(name = "rbh_risk_have_impact", joinColumns = {
        @JoinColumn(name = "RBH_RISK_RISK_DATA", insertable = true, updatable = true, nullable = false, referencedColumnName = "DATA_ID")}, inverseJoinColumns = {
        @JoinColumn(name = "RBH_RISK_PERSON_IMPACTED", insertable = true, updatable = true, nullable = false, referencedColumnName = "PERSON_IMPACTED_ID")})
    @ManyToMany(fetch = FetchType.LAZY, targetEntity = PersonImpacted.class)
    @Cascade({CascadeType.DETACH})
    @Fetch(FetchMode.SUBSELECT)
    private List<PersonImpacted> personImpactedList;

    public RiskData() {
    }

    public RiskData(String dataId) {
        this.dataId = dataId;
    }

    public RiskData(String dataId, Date dataAccidentDatetime, Date dataCreateDatetime) {
        this.dataId = dataId;
        this.dataAccidentDatetime = dataAccidentDatetime;
        this.dataCreateDatetime = dataCreateDatetime;
    }

    public String getDataId() {
        return dataId;
    }

    public void setDataId(String dataId) {
        this.dataId = dataId;
    }

    public Date getDataAccidentDatetime() {
        return dataAccidentDatetime;
    }

    public void setDataAccidentDatetime(Date dataAccidentDatetime) {
        this.dataAccidentDatetime = dataAccidentDatetime;
    }

    public Date getDataCreateDatetime() {
        return dataCreateDatetime;
    }

    public void setDataCreateDatetime(Date dataCreateDatetime) {
        this.dataCreateDatetime = dataCreateDatetime;
    }

    public String getDataEventDetails() {
        return dataEventDetails;
    }

    public void setDataEventDetails(String dataEventDetails) {
        this.dataEventDetails = dataEventDetails;
    }

    public String getDataLocate() {
        return dataLocate;
    }

    public void setDataLocate(String dataLocate) {
        this.dataLocate = dataLocate;
    }

    public String getDataPreliminaryResolve() {
        return dataPreliminaryResolve;
    }

    public void setDataPreliminaryResolve(String dataPreliminaryResolve) {
        this.dataPreliminaryResolve = dataPreliminaryResolve;
    }

    public Date getDataUpdateDatetime() {
        return dataUpdateDatetime;
    }

    public void setDataUpdateDatetime(Date dataUpdateDatetime) {
        this.dataUpdateDatetime = dataUpdateDatetime;
    }

    public Profile getProfileCreate() {
        return profileCreate;
    }

    public void setProfileCreate(Profile profileCreate) {
        this.profileCreate = profileCreate;
    }

    public Profile getProfileUpdate() {
        return profileUpdate;
    }

    public void setProfileUpdate(Profile profileUpdate) {
        this.profileUpdate = profileUpdate;
    }

    public SeverityLevelDetail getSeverityLevelDetail() {
        return severityLevelDetail;
    }

    public void setSeverityLevelDetail(SeverityLevelDetail severityLevelDetail) {
        this.severityLevelDetail = severityLevelDetail;
    }

    public Workgroup getWorkgroupConnected() {
        return workgroupConnected;
    }

    public void setWorkgroupConnected(Workgroup workgroupConnected) {
        this.workgroupConnected = workgroupConnected;
    }

    public Workgroup getWorkgroup() {
        return workgroup;
    }

    public void setWorkgroup(Workgroup workgroup) {
        this.workgroup = workgroup;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    @XmlTransient
    public List<PersonImpacted> getPersonImpactedList() {
        return personImpactedList;
    }

    public void setPersonImpactedList(List<PersonImpacted> personImpactedList) {
        this.personImpactedList = personImpactedList;
    }

    public MainEvent getMainEvent() {
        return mainEvent;
    }

    public void setMainEvent(MainEvent mainEvent) {
        this.mainEvent = mainEvent;
    }

    public MainCause getMainCause() {
        return mainCause;
    }

    public void setMainCause(MainCause mainCause) {
        this.mainCause = mainCause;
    }

    public SubEvent getSubEvent() {
        return subEvent;
    }

    public void setSubEvent(SubEvent subEvent) {
        this.subEvent = subEvent;
    }

    public SubCause getSubCause() {
        return subCause;
    }

    public void setSubCause(SubCause subCause) {
        this.subCause = subCause;
    }

    public Profile getProfileReviewLevel1() {
        return profileReviewLevel1;
    }

    public void setProfileReviewLevel1(Profile profileReviewLevel1) {
        this.profileReviewLevel1 = profileReviewLevel1;
    }

    public Profile getProfileReviewLevel2() {
        return profileReviewLevel2;
    }

    public void setProfileReviewLevel2(Profile profileReviewLevel2) {
        this.profileReviewLevel2 = profileReviewLevel2;
    }

    public Profile getProfileReviewLevel3() {
        return profileReviewLevel3;
    }

    public void setProfileReviewLevel3(Profile profileReviewLevel3) {
        this.profileReviewLevel3 = profileReviewLevel3;
    }

    public String getDataCQI() {
        return dataCQI;
    }

    public void setDataCQI(String dataCQI) {
        this.dataCQI = dataCQI;
    }

    public Patient getPatient() {
        return patient;
    }

    public void setPatient(Patient patient) {
        this.patient = patient;
    }

    public DrugItems getDrugItemsTrue() {
        return drugItemsTrue;
    }

    public void setDrugItemsTrue(DrugItems drugItemsTrue) {
        this.drugItemsTrue = drugItemsTrue;
    }

    public DrugItems getDrugItemsFalse() {
        return drugItemsFalse;
    }

    public void setDrugItemsFalse(DrugItems drugItemsFalse) {
        this.drugItemsFalse = drugItemsFalse;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (dataId != null ? dataId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof RiskData)) {
            return false;
        }
        RiskData other = (RiskData) object;
        if ((this.dataId == null && other.dataId != null) || (this.dataId != null && !this.dataId.equals(other.dataId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.rbh.risk.entity.RiskData[ dataId=" + dataId + " ]";
    }
}
